﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfDemo.Common
{
    public partial class PageInfo : ObservableObject
    {

        /// <summary>
        /// 排序列
        /// </summary>
        public string? Sidx { get; set; }
        /// <summary>
        /// 排序类型
        /// </summary>
        public string? Sord { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        [ObservableProperty]
        public int pageCount = 0;

        /// <summary>
        /// 当前页
        /// </summary>
        [ObservableProperty]
        public int pageIndex = 1;

        /// <summary>
        /// 每页显示多少条
        /// </summary>
        [ObservableProperty]
        public int pageSize = 5;


        public int totalCount;
        /// <summary>
        /// 总条数
        /// </summary>
        public int TotalCount
        {
            get => totalCount;

            set {

                SetProperty(ref totalCount, value);
                this.PageCount = GetPageCount();
            } 
           
        }     
        private int GetPageCount()
        {
            int pcount = 0;
            if (totalCount == 0)
                pcount = 0;
            else
            {
                if (totalCount % pageSize > 0)
                    pcount = totalCount / pageSize + 1;
                else
                    pcount = totalCount / pageSize;
            }
            return pcount;
        }




    }
}
